package com.eshop.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.context.ApplicationContextAware;

@Component
public class BeanUtil implements ApplicationContextAware
{
    protected static ApplicationContext context;
    
    public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
        BeanUtil.context = applicationContext;
    }
    
    public static Object getBean(final String name) {
        return BeanUtil.context.getBean(name);
    }
    
    public static <T> T getBean(final Class<T> c) {
        return (T)BeanUtil.context.getBean((Class)c);
    }
}
